import { defineStore } from 'pinia'
import { ref } from 'vue'
import type { User } from '@/types/user'

// 定义用户
export const useUserStore = defineStore('cp-user', () => {
    // 用户信息
    const user = ref<User>()
    // 修改用户信息
    const setUser = (u: User) => {
        user.value = u
    } 
    // 删除用户信息
    const delUser = () => {
        user.value = undefined
    }
    // 记录回跳地址 修改回跳地址
    const returnUrl = ref('')
    const updateReturnUrl = (url: string) => returnUrl.value = url 
    return { user, setUser, delUser, updateReturnUrl, returnUrl }
}, {
    persist: true //开启pinia持久化
})